home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / utilz20x.zip / RUNEXE / RUNEXE.CPP next >
C/C++ Source or Header  |  1997-04-13  |  2KB  |  78 lines

  1. /*
  2.  * This file is part of Utiliteez v1.00.R1
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but without any warranty; without even the implied warranty of
  14.  * merchantability or fitness for a particular purpose. See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the License along with this
  18.  * library, in the file LICENSE.DOC; if not, write to the address
  19.  * below to receive a copy via electronic mail.
  20.  *
  21.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  22.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  23.  * telephone numbers and the postal address for contacts.
  24. */
  25. #include "pb_sdk.h"
  26.  
  27. #ifndef EOS
  28.     #define EOS '\0'
  29. #endif
  30.  
  31. /*
  32.  * searches for s2 in s1, not case sensitive
  33. */
  34. char*
  35. stristr( const char *s1, const char *s2 )
  36. {
  37.     char first = toupper(*s2);
  38.     size_t len = strlen(s2);
  39.  
  40.     for( ; toupper(*s1) != first || strnicmp(s1,s2,len); ++s1 )
  41.         if( EOS == *s1 ) return NULL;
  42.     return (char *)s1;
  43. }
  44.  
  45. void
  46. main(int argc, char *argv[])
  47. {
  48.     char command[512];
  49.  
  50.     /* just some safety checking here */
  51.     if( 1 == argc ){
  52.         Log(LOG_FRIEND, "runexe: no parameters specified!");
  53.         return;
  54.     }
  55.  
  56.     /* you can run batch files too... these a a bit
  57.      * different in terms that you have to load a
  58.      * copy of COMMAND.COM to execute them. We will
  59.      * simply scan the command line for a .BAT or .CMD (for OS/2)
  60.      * extension and make sure we use the *Z parameter in
  61.      * the command line (which will ensure a command.com copy)
  62.     */
  63.     if( stristr(argv[1], ".bat") || stristr(argv[1], ".cmd") )
  64.         strcpy(command, "*Z");
  65.     else command[0] = EOS;
  66.  
  67.     /* since separate arguments are passed separately, we
  68.     * will collect them all here in our command line:
  69.     */
  70.     for( int i = 1; i < argc; ++i ){
  71.         /* this is needed to ensure at least one whitespace */
  72.         sprintf(&command[strlen(command)], " %s", argv[i]);
  73.     }
  74.  
  75.     Log(LOG_FRIEND, "runexe: exec '%s'", command);
  76.     MenuFunction(MENU_SHELL, command);
  77. }
  78.